var HOST = 'https://wx-api.shanhi.cn';

const http = {

  get: function (url, params, success, fail) {

    const token = wx.getStorageSync('token')
    wx.request({
      url: HOST + url,
      data: params,
      method: 'GET',
      header: {
        'token': token
      },
      success: function (res) {
        console.log(res)
        const result = res.data
        if (result.code == '200') {
          success(result.data)
        } else {
          if (fail) fail(result)
        }
      },
      fail: function (res) {
        console.log(res)
      }
    })
  },

  post: function (url, params, success, fail) {
    const token = wx.getStorageSync('token')
    wx.request({
      url: HOST + url,
      data: params,
      method: 'POST',
      header: {
        'token': token
      },
      success: function (res) {
        console.log(res)
        const result = res.data
        if (result.code == '200') {
          success(result.data)
        } else {
          if (fail) fail(result)
        }
      },
      fail: function (res) {
        console.log(res)
      }
    })
  }
}

module.exports = http